package com.ysyc.driver_ee.tools;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * <p>描述：(这里用一句话描述这个类的作用)</p>
 * 作者： Chan<br>
 * 日期： 2018/10/15 11:29<br>
 * 版本： v1.0<br>
 */
public class StringUtils {
    public static String getPoint(double longitude, double latitude) {
        //根据第一个点的位置 获得第二个点的位置
        String longitudes = String.valueOf(longitude) + "000000";
        String latitudes = String.valueOf(latitude) + "000000";
        String result = longitudes.substring(0, longitudes.indexOf(".") + 7) + "," + latitudes.substring(0, latitudes.indexOf(".") + 7);
        LogUtils.e("计算的经纬度为：" + result);
        return result;
    }

    ;

    public static String sHA1(Context context) {
        try {
            PackageInfo info = context.getPackageManager().getPackageInfo(
                    context.getPackageName(), PackageManager.GET_SIGNATURES);
            byte[] cert = info.signatures[0].toByteArray();
            MessageDigest md = MessageDigest.getInstance("SHA1");
            byte[] publicKey = md.digest(cert);
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < publicKey.length; i++) {
                String appendString = Integer.toHexString(0xFF & publicKey[i])
                        .toUpperCase(Locale.US);
                if (appendString.length() == 1)
                    hexString.append("0");
                hexString.append(appendString);
                hexString.append(":");
            }
            ;

            String result = hexString.toString();
            return result.substring(0, result.length() - 1);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static List<String> getListString(String stringSplit) {
        if (!TextUtils.isEmpty(stringSplit)) {
            String[] splitStart = stringSplit.split(",");
            List<String> list = new ArrayList<>();
            for (int i = 0; i < splitStart.length; i++) {
                list.add(splitStart[i]);
            }
            return list;
        }
        return null;
    };


}
